Yet another refactor attempt