Entire rewrite for 1.7