Refactored: separated functions