Refactored, cleaned up.