tied up some of the function by adding extra functions, we might want to put these into a separate library file. Also a lot more variables have been made constants.