added second part of the logic