More error checking and better error handling

Signed-off-by: Ken Barber <ken@bob.sh>