Copied code from 'bbcom'.