Removed some unnecessary whitespace
Added sendData function to reduce code duplication