copy codes from https://code.google.com/p/zzmfish