small corrections and refactoring