adding changes after feedback from @leggetter