Almost done. Some debugging to finish