Implements command resolution (with tests)