fixed many minor bugs.