Fixed up trapped algorithm