Refactored some smelly code