Fixing bug with functions