changed for-loop behavior, added reading code from file