UNTESTED CHANGES: Added some additional checks for sending out data.