some code from oschina