Added error checking

Fixed error