Added more robust checking