fully functional but incredibly inefficient. results verified with mathematica