Fixed crash in some cases