Major update and rewrite