removed use of $array[-1] (not portable)