includes functional implementation and error handling