Added tests for tuple casting, debugged minor errors, tidied up casting in Javascript