fixing #18 and some refactoring