Refactored, added JavaDoc