Major changes and rewrites