Totally rewritten registry handling.