Improvements based on code review from @akbargumbira