cleaned up code to be more understandable?