refactor: extract entry function logic