Fixing bug in intent function