bug fixesl; threading