changed location of stdin flush function