did a little refactoring and made the code a little more readable