refactored to the max