sync'ed code from 0.0.8.1 tag into here