cleaned up some of the code a bit