Fixing the code so that it works