Implemented modifications from Tokuya Kameshima.