Refactored the Register JS code a bit