fix error and clean code