writemsg functions, better handling of kill