Fixed bug which causes crashes