improved error-checking/handling