Completed rewrite of everything