Refactored and cleaned up core Untwister code