translation from old C++ version