refactoring to deal with permalinks