extracted the code into 3 methods