fix for issue 391 and issue 307