problems with sparki's bluetooth module

Hi. I’m having problems with the bluetooth modules.

I can communicate with it sometimes sending and receiving messages successfully to and from my mac.

and even so it usually hangs then restarts in after I send a command to it (status led blinks red) and the Sparki logo disappears before showing up again.

This is my code:
gist.github.com/mithi/f3c3f60ca22981d87bbd

but sometimes I get this error as well:
imgur.com/oaxaOj1

I hope someone can help me, thanks!