Prepare to upstream merge. Some fixes and improvments