refactor redundant code