Fixes NPEs, warnings. Removes unnecessary fields to reduce the memory footprint.