fix bug in bak function