fixed bugs with indexoutofbounds exceptions. SHOULD be bugfree now.