Improved optimization; added no-reorder option