fix bugs and improve code;