fixed isValid function to check for valid blocks