Added some safety checks