cleaning up code

fixing some bugs I found and cleaning up the code