unoptimized version of method 2