Several Bug fixes