use lock when sending data
Added file comments