Cleaned up Code

Deleted unnecessary code and moved code from main into separate
functions