partial debugging of the second implementation option. Still needs some work to function correctly