For loop refactored and Javadoc added for return statement