Fix issue with out of bounds array
Fix some more bugs