Finished major rewrite