Added functions instead of duplicate code