Modified getLast to address Ji's output requirements