fix error from rearranging code order