extract some methods, add comments