Some refactoring and basic support for limits