refactoring and implemented helper methods