Refactored into awesomeness