fix bugs from commit 00f215cfbb668ec2c1f1557e4ddee5d80994f7a3