finalizing and refactoring