Implemented max loop length