fixed nasty indexoutofrange thing