Cleaned up the code a bit and added hash validation to sent messages