tst
refactored code to make methods easier to read.