Fixes #7
Code refactoring