Re arranged some code. Delete obsolete code.

Re arranged some old code from deleted class into the new one. Deleted
obsolete code. Fixed a typo in a variable name.