added some print statements for debugging
returns correct results