Merged some updates

Merged some updates from few forks.

Sorry - it's broken and needs some rework. Please cancel this request.