fix bugs
fix bugs and add functions