Added safe guards in case pointers end up with an invalid value