This is a C++ rewrite of well-known utility