Move resolve to its own file. Make matching better.