put most of the programme into 3 methods