refactored, added functionality