some rearranging and fixes