Some refactoring to make prefix handling more flexible