Added some data integrity safeguards