Porting the final script to Coffee. Still some fixing TBD.