Refactor to use linq