modularing the functions for tidier code