fixed invalid echo -n calls, which didnt work under /bin/sh
added error checking