added additional comments and checks for empty files