Serialize return code correctly in binary form, minor cleanup