Fixed many minor bugs