Rearrange and fix unsorted variables, fix #34