fixed order, clean up code