refactor and create test for  method