Refactor market.js

Fix #33