fix bug with using index -1