fixed some of the code to look a little neater