Working code produces results

This code was rewritten and seems to work