fixed bug that can crash the db