function reordering bug, debugged