updated with a bug fix and better documentation