some fixes, some refactoring, a little new stuff