Fixed code based on PR comments