First refactor attempt