Added javadocs and made refactorings where appropiate