Moved some functions to make main-file more tidy