Added a median function to the script.  Enjoy!