Implemented the accept function, and a helper function