Added export feature. Fixed some bugs