Removed lots of dead code, minor fixes