add some safety checks