Refactor prefix handling