refactored a method and added documentation