working almost perfectly. probably should preallocate memory to center and rect things