Refactor according to @tust13 suggestion
Improve test coverage