Reworked javascript for easier extension