P17: Rewrote Java code for clarity.