Refactored. Fixed #113