working code - rough, have to change input file by hand