fixed a bug and cleaned up some old code.