Fixed crash caused by order of operations