fixes in active record query for reorder