random fixes and formatting
replace fprintf to stderr with printf