Extracted three methods in order to improve readability.