Added error checking
Added error checking