General code update

fixed issues, added more line comments