with David's changed anf fix of placeInPQ function - adding the
previouselement variable