added some proper minimal (but effective) error handling