Refactored SIP arrange JS.

Cleaned up SIP arrange JS, fixed minor issue, and moved JS out of
HTML template.