Extracted several functions for readability