cleaned up main by moving some of the code into a function in the new implementation file. Also added a header.