big refactoring + proper type inferrence close #14 #15 #16