Undefined variable error fixed