checks improved
adding PUBLISH packet writing
bugfix