change from exec to spawn to capture stdin/out of child process
clean up code