extracted the left-insertion logic into a separate module