refactored to remove nil issue