Fixed some faulty indexes and parameters. Also added some more debug information.