fix the fragment mode

Rebase of the PR #38 and one new commit to fix comments of @monperrus.