ported code to moonscript