Refactored slightly.