fix bugs and code