added defense, and cleanup + comments
some comments and improvements