apply changes from @phoet comments