Fixed several minor bugs