fix debug option and refactor