fix bugs and rename functions