Refactor and adjust folding