Adding cmnetwork.js code
Added some additional error checking