Fixed several minor bugs located during junit testing