Refactored, cleaned up