Fixed the checking logic