Reworked contains() code and added docstrings