Moved the functions in their respective files and some clean up