cleaned up a lot of the code