updated to include extra checking