Refactored to a more clean state