Separated code into function files to make reading easier