fixed many minor bugs