fixed write quadratic overindexing problem