correct bug in internal function