Fix restrict

This partially fixes #1026. All tests pass.