Minor refactoring
Overall fixes