refactored,apply type hint to parameter and move logic to private method