corrected impl of last, corrected tests