Various fixes and improvemnts