some refatoring
better scoped
some refactoring