Fixing bug in code