/controllers/, /lib/, /models/ & /scripts/: fixed various JS errors and error-prone code