optimized algorithm, cached mappings for both conversions and completed implementation