code cleanup
improve decoding of corner cases