Comments and Functions

Created function and reduced the complexity by breaking the if loops in
the code and putting them in separate functions