Rewritten some bulgy code.