added better exceptions and error checking
fixed broken test