beautify and error check