Top two sections refactored using functions