Refactored a lot