Implemented dig function

implemented the dig function and some minor changes to other places
Create demo.py
fixed merge errors