Create general function for set_background

This issue, is part of many issues aiming at improving the overall readability and sturcture of the main branch code, by creating individual generel functions.