Improve and optimize clist functions. Add unittests.