refactored part of application process to get rid of repeated code