Added error checking to Cp function