Misc patches I needed to make it work properly

See each patch description