refactor for more generic approach