reformat code and move unchanging parts on top