fixed the functions related to folding