add reading file, refactor code