Extracted most code into 3 methods