Yak shaving... more refactoring and bug fixes