Improved PM and PubM JS

more well behaved javascript