bugfix, wrong index
some bug fixes, heavy testing will be necessary ;)