* fixed some more indexing problems
 * some code refactoring