* many fixes and refactorings