cleaned up dead code and fixed minor bugs