Refactoring and minor touch up