refactor crappy error code