Added error-checking