fixed remaining bugs
cleaned up code