Added isValidObject function