fixed issues with compatibility, bashisms and optional max time limit

just take a look. i guess this might work better :)

couldn't even start the script at first since nowadays bash is not always linked against /bin/sh. I've also tried to make the code a bit more readable.

there might be erros in there, it's late,..