improved error checking fixes #15