removed redundant check in the loop