Added a multitude of safety checks