Refactor code from "C"-like to js-like idioms