Fix crash

Here is complete solution to fix crash.