wrapper and lots of clean up to make it work w/ drupal