cleaned up serial_matrix code organization