Fixing some edge case JS errors