adding export code and bug fixes