Big pull request with a lot of fixes

Big pull request with a lot of fixes