Various fixes, removing of old and unnecessary code.

Will comment on some of the changes.