(1) More error checking
(2) Minor refactoring