first refactor, runs with small test, output is not correct