Updated the functionality; now works a lot smoother