code cleanup and ctest fixed