refactored limit logic