refactored method and added comment to javadoc