Function was not working, added some tweaks to let it run