bugfix: wrong index in gradient
minor changes