Refactoring and cleanup

- Work-in-progress.