Fix seg fault, introduce debug and fix receiveCommandtest