Added error checking
Fixed cmake file