Major changes to allow different type of permalinks. Must be refactored, of course