Working code with examples at bottom of the file