[FOLD] Clean up some functions and refactor