Fix bug with published item _id
Fix memory leak and other tweaks