Make limits and offsets more robust. Add more tests for edge cases concerning them.