copied code from 61c