Integrating Praveen Devarao's changes from
http://rubyforge.org/tracker/index.php?func=detail&aid=29775&group_id=2361&atid=9176