THIS IS THE C++ VERSION OF SULTAN'S STUFF

seems legit.