Refactored apfy.js. Also, now state function can now return a state only if a transition is supposed to happen.