Refactoring to fit best practices