added some error checking for pointers