known working version; fix bug