removed duplication in loop