Bug fixes and modifications