A lot of code change for issue #79 . Still experimental
Fix bug #80