merging Pavel (github: rasstreli)'s changes