Reordered functions and initialized a main function to handle and organize calls