Move some code to header file