Comments and plot

Added comments to code. Plot graph if output file is not provided.