Use different limits in shared and exclusive modes

The code is still ugly, the code is still slow.