Fixed some refactoring bugs and removed some defunct code.