fixed #11; fixed #12 - refactorings and fixes