added export functionality and fixed bug