Fix #2: thorough error checking on all occasions