Refactoring and clean up (continued)