fixing concurrent modification issue and refactoring
adding null check