refactored to do synchronous stdin read