Fixed portTICK_RATE_MS bug.
Moved additional variables into struct.
Several changes are per review comment.