refactored code a bit, should be working as expected now