Refactor + added documentation