Code cleanup, fix from Pavel Pimenov
Merge pull request #24 from pavel-pimenov/master

Small optimization
More fixes from Pavel Pimenov
Undo
More fixes from Pavel Pimenov