Some cleanup & refactoring of #70