Clean up, refactor js code, removed unused templates