Added further error checking