Improve Functionality

Added/reworked javascript to get the functionality much more intuitive
and automatic.