Put code from main into seperate functions