Fixed URL encoding bug for time ranges
Made legend generation more flexible and fixed minor bugs.