A4988 and CNC shield problem

I built a setup where CNC shield is connected to the Arduino Uno. CNC shield is powered by a 12V, 5A source. During testing, I noticed that the motor spins in place a few times before starting to rotate properly, and its direction is random. I use A4988 and motor model is17HS4401S
I use laser grbl(v1.1) to control it. I download from here(GitHub - gnea/grbl: An open source, embedded, high performance g-code-parser and CNC milling controller written in optimized C that will run on a straight Arduino)
How can i solve it