fix bugs and add code