Refactoring, small bufixes