Extracted code into various methods for readability