some error-checking and comments