Cleanup + refactoring + small fixes