A lightweight Finite State Machine in Javascript