Refactored and cleaned up the scheduler javascript code.