Added tests, fixed Javascript error