refactor final if clauses of module return