Refactoring
Several small fixes