Refactor the dual mode implementation