Added Level encoding/decoding

Created associated unit tests, updated documentation and refactored
common code.