Refactor games controller js