Added shoutout to sebastian seilund as original author of majority of this code.