minor refactoring and seperating methods out to respect single responsibility principle