Replace sorcery with some black magic. Some cleanup and fine tuning still needed.