Add defensive checks