Refactored code and made comments align with javadocs style