cleans factor graphs to make it linkable and clean