refactor and ctor and fixes