clean up messages.js and its implementation