Various corrections and bug fixes