fix bugs and log func