Code

More refactoring to reduce copy-n-paste duplication.