Refactored the logic quite a bit
Refactored a lot of things