add few safety checks