refactor for cleaner code path