Added more error checking in add()