Back porting some changes from pro.

See:

https://github.com/GigaOM/legacy-pro/pull/552#discussion_r4486864
https://github.com/GigaOM/legacy-pro/pull/552#discussion_r4486838