Various fixes and improvments