Split functions into seperate files & fixes