extract inline class to simplify reading the code
extract submethods to simplify code