i hate javascript even more but at least my legend's working