cleaned up code (a lot)