Refactored completely