A lot of changes and fix for issue #3