working export, though a bit ugly...