added more logic checks