Bringing some important changes from master to branch-0.4

Bringing some important changes from master to branch-0.4

Ready to mege