Fixed a bug which caused crashes