Massive refactoring of backwards and bug fixes.