Fixes several minor bugs