code cleanup and get exporting working