optimize messages; specifically, clean up messages.js