Bug fix on checking routine