all the code belongs to sp4ke, who generously gave permission to use his code.