Patch to fix the above issues.
Worked on by @yonaslegesse and @tsega