now reporting to file, fixed bugs, cleaned code