Added Debug Messages and Error handling. Some Comments still missing.