fixed a few logic bugs and removed some old code