Fixed log messages.
Fixed a bug.
Added length checks.