Fix minor bugs, seperate code and add no main function error