Slight refactoring and cleanup