Fixed #1087
Merge pull request #1089 from fruitwasp/refactor

Fixed #1087