Add folding support

Closes #10.