added testing to encode and decode