refactored stdin program a bit to make it cleaner