parse file method to avoid repeating.