original code directly from http://baliga.systemsbiology.net/drupal/?q=node/38