Fix compatibility with 1.8.7 .
Refactor.
Merge pull request #1354 from namusyaka/fix-compat-with-1.8.7

Fix compat with 1.8.7