extracted voldemort functions from khan.cpp