First commit after rewrite for better coding style per ljharb's comments