cleaned up loops and instance variables