fixed several bugs

by PavelVolkovitskij