Refactored a few components. Still the same basic algorithm.