added handlers for NULL pointers in all functions