Misc

Miscellaneous additions and refactoring.