Reorganization of logic and update functions, bug fixes for CL functions