multiple functions work, fixed some issues in for loops, adjusting for different cases