refactored part1 and part4. added part 5. added avg python script