refactored two methods into one