Initial refactor to a cleaner design