Minor optimization to prime functions