fix some minor bugs in implementation