done some refactoring
updated version