Fixes, many fixes and refactorings