Improved environment handling and other fixes
Added error for unused data and ignored private struct field in decode.