Removed a for loop

Made the replacement flow into the rest of the code, replaced a for loop
with a function and llplys. Might be slow, though