Refactoring code to clean everything up