added edge cases to decoding