refactored, added documentation