fixed a type and some minor bugs