based on pr #186 and fix issue #180