improved myLast solution with guards