One big bug fix (doh) and some error checking