Fixed #3 & minor refactorings