smth
some improvements and refactoring