Memory violation bugfix by Norikazu Sugiura