refactor for more complex scenarios