Refactor redundant code