Refactored to acceptable speeds.