Add doc comments, fix golint issues and close file descriptor after use.