Refactored so I can reuse it in another place.