a few changes and refactoring