code cleanup, made runnable, prepared to MC 2.2+ migration