sync stdout so that log file is unbuffered

also refactored startup logic