refactored some methods into inner methods