Here is the meat. I wrote this for a work project and i think its cool.