refactor: remove redundant code, merge functions