Refactored embarrassing code