Fixed error with long chains not working due to loop cut off in the wrong place