Refacto with more general methods
Add javadoc