Fix crashes caused by a9ad5ee494221b5ba4b59527e4c3535527a23eac

For some reason, I've merged referenced commit without actually testing it.
Sorry.

Signed-off-by: Gregory Petrosyan <gregory.petrosyan@gmail.com>