warning: array subscript is above array bounds and some cleanup