Reimplement rectification more elegantly