Added comments
Added frequency check before writing to file