modified some code to be more readable