Divide out of the loop
Move check up a level
Add javascript
Fix up java