Thread improvements

Replaced the two racing threads - program (main) and input - with
two command generating threads - program and input - and a command
receiving thread (main).