improved algorithm

removed unnecessary variable creation