Small JS refactoring.

Very tiny JS rewriting if you aprrove