change error codes, some minor code cleaning