procedures and continued refactoring with templating functions