added debug option and some useful debug statements