work on #328
work on #328 and fix #327 again in a more general way