added check for nil