Simplified the code.
Added class for postMessage().