moved title to main; some rearrangements