Minor bug fixes, primarily checking and cleaning code.