refactor types, add dialyzer check, fix bugs