Various fixes and modifications