Some bugs fixed.

Signed-off-by: Yuriy Rusinov <yrusinov@gmail.com>