improved performance for issue 1 solution