remove bugs and fix coding style