Controlling the movement Direction in Corona

Hi, 

I’m making a game in which I want to make the ball bounce off the left and right side of the screen. At the same time if I tap, the ball should reverse its direction of motion. The ball only moves on X-axis.

Here is the code I wrote:

[lua] 

 local function directionReverseOnTap()

    xDirection = xDirection * -1

end

local function ballMove()

    ball.x = ball.x + xSpeed * xDirection

      if (ball.x >= screenRight - ballRadius) or (ball.x <= screenLeft + ballRadius) then

        xDirection = xDirection * -1

    end

end

[/lua]

Only problem is, if I tap while the ball is close to the edge and about to bounce off, it gets stuck. Otherwise it works fine. Kindly tell me if there is a problem with the code. Thank you.