Code cleanup, fix from Pavel Pimenov