Refactored to use Linq