updated for nil checks