Ok, so I reworked the function a little bit. Take a peek :)