Improve code based on GH comments