Fixing JavaScript error