Fixes for bugs with toJSON in Element