refactored code to include inspection function, avoid repition