Fixing the code so that it works

credits go to @ManiacTwister