Refactored my code. TRIED to make it more understandable