D solved, need optimizations