Little refactor of main routine