Issue #191

Refactor + Bug fix + Tests