refactored to make more generic (split modules out of framework), fixe
some bugs