Limits fixes and refactoring, still one test case failing